package com.example.jerry.test;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.example.loginandpaytools.LoginAndPayToolSDK;
import com.example.loginandpaytools.Support.Configuration;
import com.example.loginandpaytools.Utils.HttpCallbackListener;
import com.example.loginandpaytools.Utils.LoginCallbackListener;

public class LoginActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);

        setConfig();

        Button btn = (Button) findViewById(R.id.test_login);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /**
                 * 打开登陆界面
                 */
                LoginAndPayToolSDK.openLoginInterface(LoginActivity.this);
            }
        });

        Button btn2 = (Button) findViewById(R.id.test_actor_login);
        btn2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /**
                 * 调用角色登陆接口,只需实现onFinish()以及onError()方法
                 */
                LoginAndPayToolSDK.roleLogin(LoginActivity.this, new HttpCallbackListener() {
                    @Override
                    public void onFinish() {
                        Toast.makeText(LoginActivity.this, "登陆成功", Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onFinish(String code) {

                    }

                    @Override
                    public void onFinish(String username, String password) {

                    }

                    @Override
                    public void onError(Exception e) {
                        Toast.makeText(LoginActivity.this, e.getMessage(),Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });

        /**
         * 处理登陆成功之后的事件
         */
        LoginAndPayToolSDK.handleLoginEvent(new LoginCallbackListener() {
            @Override
            public void succeedLogin(String code) {
                Toast.makeText(LoginActivity.this, code, Toast.LENGTH_SHORT).show();

            }
        });


    }

    private void setConfig() {
        //相关的值需要替换
        //uid
        Configuration.setUID(5421);
        //用户长期token
        Configuration.setTOKEN("54217f145b998297c22c0a3ff735d4270024");
        //角色id
        Configuration.setRoleId(262);
        //角色名字
        Configuration.setRoleName("南阳尚香");
        //角色等级
        Configuration.setRoleLevel(1);
    }

}
